package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.domain.VisitRecord;
import com.zzyl.nursing.service.IElderService;
import com.zzyl.nursing.service.IVisitRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 来访记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/nursing/visit_record")
public class VisitRecordController extends BaseController
{
    @Autowired
    private IVisitRecordService visitRecordService;
    @Autowired
    private IElderService elderService;

    /**
     * 查询来访记录列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(VisitRecord visitRecord)
    {
        startPage();
        List<VisitRecord> list = visitRecordService.selectVisitRecordList(visitRecord);
        return getDataTable(list);
    }

    /**
     * 导出来访记录列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:export')")
    @Log(title = "来访记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisitRecord visitRecord)
    {
        List<VisitRecord> list = visitRecordService.selectVisitRecordList(visitRecord);
        ExcelUtil<VisitRecord> util = new ExcelUtil<VisitRecord>(VisitRecord.class);
        util.exportExcel(response, list, "来访记录数据");
    }

    /**
     * 获取来访记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(visitRecordService.selectVisitRecordById(id));
    }

    /**
     * 新增来访记录
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:add')")
    @Log(title = "来访记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VisitRecord visitRecord)
    {
        return toAjax(visitRecordService.insertVisitRecord(visitRecord));
    }

    /**
     * 修改来访记录
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:edit')")
    @Log(title = "来访记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VisitRecord visitRecord)
    {
        return toAjax(visitRecordService.updateVisitRecord(visitRecord));
    }

    /**
     * 删除来访记录
     */
    @PreAuthorize("@ss.hasPermi('nursing:visit_record:remove')")
    @Log(title = "来访记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(visitRecordService.deleteVisitRecordByIds(ids));
    }
    /**
     * 获取来访记录列表
     */
    @GetMapping("/all")
    public AjaxResult all()
    {
    	return success(elderService.getAll());
    }
}
